package day0223

import . "gocode/algorithm/utils"

func reversePrint1(head *ListNode) []int {
	var stack []int
	for head != nil {
		stack = append(stack, head.Val)
		head = head.Next
	}
	for i := 0; i < len(stack)/2; i++ {
		stack[i], stack[len(stack)-1-i] = stack[len(stack)-1-i], stack[i]
	}
	return stack
}

var res []int

func reversePrint(head *ListNode) []int {
	res = make([]int, 0)
	help(head)
	return res
}

func help(node *ListNode) {
	if node == nil {
		return
	}
	help(node.Next)
	res = append(res, node.Val)
}
